import diff from "./diff";

export default class Component {
  constructor(props) {
    this.props = props;
  }

  setState(state) {
      this.state = Object.assign({}, this.state, state)
      // 获取最新的 virtualDOM
      const virtualDOM = this.render()
      // 获取 旧的 DOM节点
      const oldDOM = this.getDOM()
      // 获取容器
      const container = oldDOM.parentNode
      // 对比新旧 virtualDOM, 更新视图
      diff(virtualDOM, container, oldDOM)
  }

  updateProps(props) {
      this.props = props
  }

  setDOM(dom){
      this._dom = dom
  }

  getDOM() {
      return this._dom
  }

  // 生命周期函数
  getDerivedStateFromProps() {}
  componentDidMount() {}
  shouldComponentUpdate(nextProps, nextState) {
    return nextProps != this.props || nextState != this.state;
  }
  getSnapshotBeforeUpdate() {}
  componentDidUpdate(prevProps, preState) {}
  componentWillUnmount() {}
}
